<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Question_m extends Model{
    function Question_m(){
        parent::Model();
    }
    
    function getQuestion($username,  $password, $number){
        
        $ver = $this->db->query("SELECT * from users WHERE username = '$username' AND password ='$password'");
        
        if ($ver->num_rows()  == 1){
            $question = $this->db->query("SELECT * from question WHERE number = $number");

            if ($question->num_rows() > 0){
                foreach($question->result_array() as $hsl){
                    $result = $hsl;
                }
                return $result;
            }
            else{
                return 0;
            }
        }
		else
			return 0;
    }
	
	function getNumQuestion(){
		$ver = $this->db->count_all('question');
		return $ver;
	}
	
	function postAnswer($username, $number, $answer)
	{
		$ver = $this->db->query("SELECT * from users WHERE username = '$username'");
        
        if ($ver->num_rows()  == 1){
            $question = $this->db->query("INSERT ");

            if ($question->num_rows() > 0){
                foreach($question->result_array() as $hsl){
                    $result = $hsl;
                }
                return $result;
            }
            else{
                return 0;
            }
        }
	}
	
}
?>

